﻿using System.Collections.ObjectModel;
using Catel.Data;
using Catel.MVVM;

namespace Catel.Articles._03___MVVM.Examples.UserControlWithParameter
{
    /// <summary>
    /// Company view model.
    /// </summary>
    public class CompaniesViewModel : ViewModelBase
    {
        #region Constructor & destructor
        /// <summary>
        /// Initializes a new instance of the <see cref="CompaniesViewModel"/> class.
        /// </summary>
        public CompaniesViewModel()
            : base()
        {
            // Create 3 companies
            CompanyCollection = new ObservableCollection<Models.Company>();
            CompanyCollection.Add(DataHelper.CreateCompany("My first company", 3));
            CompanyCollection.Add(DataHelper.CreateCompany("My second company", 5));
            CompanyCollection.Add(DataHelper.CreateCompany("My third company", 1));
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the title of the view model.
        /// </summary>
        /// <value>The title.</value>
        public override string Title { get { return "Company"; } }

        #region Models
        #endregion

        #region View model
        /// <summary>
        /// Gets or sets the companies.
        /// </summary>
        public ObservableCollection<Models.Company> CompanyCollection
        {
            get { return GetValue<ObservableCollection<Models.Company>>(CompanyCollectionProperty); }
            set { SetValue(CompanyCollectionProperty, value); }
        }

        /// <summary>
        /// Register the CompanyCollection property so it is known in the class.
        /// </summary>
        public static readonly PropertyData CompanyCollectionProperty = RegisterProperty("CompanyCollection", typeof(ObservableCollection<Models.Company>));

        /// <summary>
        /// Gets or sets the selected company.
        /// </summary>
        public Models.Company SelectedCompany
        {
            get { return GetValue<Models.Company>(SelectedCompanyProperty); }
            set { SetValue(SelectedCompanyProperty, value); }
        }

        /// <summary>
        /// Register the SelectedCompany property so it is known in the class.
        /// </summary>
        public static readonly PropertyData SelectedCompanyProperty = RegisterProperty("SelectedCompany", typeof(Models.Company));
        #endregion
        #endregion

        #region Methods
        #endregion
    }
}
